package id.net.iconpln.bb.server.dao;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository("ReportDao")
public class ReportDao {
	@Autowired private SessionFactory sessionFactory;
	
	public List<Map> getLaporanBaBongkar(String kode, Map map) {
		// TODO Auto-generated method stub
		List<Map> lMap = new ArrayList<Map>();
		try{
//			String path = "report/Berita_acara_pembokaran1.jasper";
//			Map<String, Object> parameters = new HashMap<String, Object>();
//            parameters.put("no_bongkar", "001/SRL/2011");
			
			String path = map.get("path").toString();            
            Session session = sessionFactory.getCurrentSession();
            Connection con = session.connection();
			JasperPrint jPrint = JasperFillManager.fillReport(path, map, con);
			JasperExportManager.exportReportToPdfFile(jPrint, "report.pdf");		
			map.put("message", "1");
			map.put("pathResult", "report.pdf");
		}catch (Exception e) {
			e.printStackTrace();
			map.put("message", e.getMessage());
		}
		lMap.add(map);
		return lMap;
	}
}
